<script setup>
import { getdscdlkbNow, getgxdlxxNow } from '@/api/processClassNow.js'
import { formatHeaderData, generateTwoDimensionalArray } from '@/utils/globalMethod'

import { formatMoney } from '@/utils/globalMethod'
const key = ref(1)
const total = ref()
const active = ref('')
const config = reactive({
  data: [],
  header: ['工单单号', '产品名称', '规格型号', '工序', '工单总数', '累计良品', '待生产数量', '等待时间', '开工时间'],
  headerBGC: 'rgba(0,0,0,0)',
  oddRowBGC: 'rgba(0,0,0,0)',
  evenRowBGC: 'rgba(0,0,0,0)',
  align: ['center', 'center', 'center', 'center', 'center', 'center', 'center', 'center', 'center', 'center'],
  columnWidth: [70, 200, 240, 240, 120, 120, 120, 140, 140, 120],
  rowNum: 10,
  index: true,
  carousel: 'page',
  waitTime: 1000 * 20
})
const keyResize = () => {
  nextTick(() => {
    setTimeout(() => {
      key.value++
    }, 100)
  })
}

/**
 * @description: 渲染滚动的数据
 * @param {*} data
 */
const renderScrollData = data => {
  config.data = data.map(item => {
    item.Quantity = formatMoney(null, item.Quantity)
    item.GoodQty = formatMoney(null, item.GoodQty)
    item.dscsl = formatMoney(null, item.dscsl)

    if (item.gdzk === 2) {
      for (let k in item) {
        item[k] = formatHeaderData(item[k], 'red')
      }
    } else if (item.gdzk === 1) {
      for (let k in item) {
        if (k === 'dgs' && item[k] > 10) {
          item.dgs = formatHeaderData(item['dgs'], 'red')
        } else {
          item[k] = formatHeaderData(item[k], '#0084ff')
        }
      }
    } else {
      for (let k in item) {
        if (k === 'dgs' && item[k] > 10) {
          item.dgs = formatHeaderData(item['dgs'], 'red')
        }
      }
    }

    return [
      item.MkNo,
      item.ProdName,
      item.ProdSize,
      item.OrderID,
      item.Quantity,
      item.GoodQty,
      item.dscsl,
      item.dgs,
      item.kaigongSJ
    ]
  })
}

const loadData = async () => {
  const dscdlkbNow = await getdscdlkbNow({ gx: active.value, type: 'S00636' })
  renderScrollData(dscdlkbNow.data)
  total.value = dscdlkbNow.total
}

onMounted(loadData)

onMounted(() => {
  setTimeout(() => {
    key.value++
  }, 100)
  window.addEventListener('resize', keyResize)
})

onUnmounted(() => {
  window.removeEventListener('resize', keyResize)
})
</script>

<template>
  <div class="ps_w_h_100">
    <dv-border-box8 :key="key">
      <dv-scroll-board :config="config" :key="key"></dv-scroll-board>
    </dv-border-box8>
  </div>
</template>

<style scoped lang="scss"></style>
